package battlecruiser.board;

import battlecruiser.board.cell.Cell;
import battlecruiser.board.cell.CellStatus;
import battlecruiser.board.cell.coordinate.Coordinate;
import battlecruiser.ship.placement.ship.Ship;
import battlecruiser.shooter.DamageReport;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * Displays results of players' shots on enemy ships.
 *
 * @author Yakiv Tymoshenko
 * @since 01.09.12
 */
public class ObserverBoard extends Board {

    private static Logger LOG = Logger.getLogger(ObserverBoard.class);

    private ObservableBoard observableBoard;

    public List<Coordinate> getTargetableCoordinates() {
        List<Coordinate> result = new ArrayList<Coordinate>();
        for (Cell cell : this.getCellList()) {
            if (cell.getStatus() != CellStatus.DESTROYED && cell.getStatus() != CellStatus.DAMAGED &&
                    cell.getStatus() != CellStatus.MISSED) {
                result.add(cell.getCoordinate());
            }
        }
        return result;
    }

    @Override
    public void drawDestroyed(Ship ship) {
        super.drawDestroyed(ship);
        LOG.debug("Drawing destruction of ship " + ship);
        // Mark destroyed ship's borders as shot
        List<Coordinate> borders = locateShipBorderWaters(ship);
        for (Coordinate c : borders) {
            cells[c.getI()][c.getJ()].setStatus(CellStatus.MISSED);
        }
    }

    public ObservableBoard getObservableBoard() {
        return observableBoard;
    }

    public void setObservableBoard(ObservableBoard observableBoard) {
        this.observableBoard = observableBoard;
    }
}
